package com.bwie.controller;

import com.bwie.pojo.Goods;
import com.bwie.result.Result;
import com.bwie.service.GoodsService;
import com.bwie.utils.OssUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/goods")
@RestController
@Log4j2
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @PostMapping("/upGoodsStatus")
    public Result updateGoodsStatus(@RequestBody Goods goods){
        goodsService.updateGoodsStatus(goods);
        Result result = Result.success();
        return result;
    }

    @PostMapping("/downGoodsStatus")
    public Result downGoodsStatus(@RequestBody Goods goods){
        goodsService.downGoodsStatus(goods);
        Result result = Result.success();
        return result;
    }

    @GetMapping("/findById/{id}")
    public Result<Goods> findById(@PathVariable("id") Integer id){
        Goods goods= goodsService.findById(id);
        Result<Goods> result = Result.success(goods);
        return result;
    }

    @PostMapping("/update")
    public Result update(@RequestBody Goods goods){
        goodsService.update(goods);
        Result result = Result.success();
        return result;
    }

    @PostMapping("/upload")
    public Result<String> upload(@RequestParam("file")MultipartFile file){
        String path = OssUtil.uploadMultipartFile(file);
        return Result.success(path);
    }
}
